home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3Tp.sea Folder / Made by Marksman / Sources / mm / mmW_Floating_window.p < prev    next >
Text File  |  1994-01-16  |  12KB  |  422 lines

  1.  
  2. Unit mmW_Floating_window;
  3. {  mmW_Floating_window                                 Handle this Window }
  4. {  Copyright © 1994 George R. Cossey }
  5.  
  6.     File name: mmW_Floating_window
  7.     Function: Handle a Window 
  8.     History: 1/16/94 Original by George Cossey
  9.  
  10. }
  11.  
  12. interface
  13.  
  14.     uses
  15.         Printing,Folders,Sound,mmCommonMM_Demo,CommonMM_Demo,
  16.         {}
  17.         mmPA_My_Alert,
  18.         {}
  19.         mmD_My_Modal,
  20.         {}
  21.         mmMD_My_Movable_Moda,
  22.         mmMD_My_Modeless,
  23.         mmMD_About_Demo,
  24.         {}
  25.         UFloating_window;
  26.  
  27. procedure Init_Floating_window;
  28. procedure Close_Floating_window(whichWindow:WindowPtr);
  29. procedure Resized_Floating_window(OldRect:Rect;whichWindow:WindowPtr);
  30. procedure Update_Floating_window(whichWindow:WindowPtr);
  31. procedure Open_Floating_window;
  32. procedure Activate_Floating_window(whichWindow:WindowPtr;Do_An_Activate:Boolean);
  33. procedure Do_Floating_window(var myEvent:EventRecord);
  34.  
  35. { ======================================================= }
  36. { ======================================================= }
  37.  
  38. implementation
  39.  
  40.  
  41. { ======================================================= }
  42. { ======================================================= }
  43.  
  44.  
  45. procedure InitRecord(theWS:Floating_windowPRec);
  46.  
  47.  
  48. begin
  49. theWS^.theWindow := nil;                    { Make sure other routines know we are not valid yet }
  50.  
  51. { Set the window back color }
  52. theWS^.WindowBackColor.red  := $FFFF;  
  53. theWS^.WindowBackColor.green  := $FFFF;  
  54. theWS^.WindowBackColor.blue  := $FFFF;
  55.  
  56. theWS^.Enable_Tool_palette2 := true;                { Palette, Tool palette  }
  57. theWS^.Value_Tool_palette2 := 0;
  58.  
  59. U_InitFloating_windowRec(theWS);                            { Call user init routine }
  60. end;
  61.  
  62. { ======================================================= }
  63.  
  64. procedure LocateInstance(theWindow:WindowPtr);
  65. var
  66.     ckWS,theWS:Floating_windowPRec;
  67.  
  68.  
  69. begin
  70. theWS := nil;                            { Init to not found }
  71. ckWS := ListRecPtr_Floating_window;
  72. while (ckWS <> nil) do
  73.     begin
  74.     if (ckWS^.theWindow = theWindow) then
  75.         theWS := ckWS;
  76.     ckWS := ckWS^.Next;
  77.     end;
  78. RecPtr_Floating_window := theWS;
  79. end;
  80.  
  81. { ======================================================= }
  82.  
  83. { Routine: Init_Floating_window }
  84. { Purpose: Initialize our window data to not in use yet }
  85.  
  86. procedure Init_Floating_window;
  87.  
  88.  
  89. begin
  90. theWindowLocRec.Loc_Floating_window.h := 24;            { Set default Horz position }
  91. theWindowLocRec.Loc_Floating_window.v := 45;            { Set default Vert position }
  92.  
  93. RecPtr_Floating_window := nil;                        { No open windows yet }
  94. ListRecPtr_Floating_window := nil;
  95. MultipleAllowed_Floating_window := true;            { Init to allow multiple instances }
  96.  
  97. U_InitFloating_window;                                { Call the user window init routine }
  98. end;
  99.  
  100. { ======================================================= }
  101.  
  102. { Routine: Close_Floating_window }
  103. { Purpose: Close out the window }
  104.  
  105. procedure Close_Floating_window(whichWindow:WindowPtr);
  106. var
  107.     ckWS,theWS:Floating_windowPRec;
  108.  
  109.  
  110. begin
  111. if (whichWindow = WindowPtr(-1)) then
  112.     whichWindow := FrontWindow;
  113.     
  114. LocateInstance(whichWindow);
  115.  
  116. { See if we should close this window }
  117. if (RecPtr_Floating_window <> nil) then
  118.     begin
  119.     theWS := RecPtr_Floating_window;
  120.     
  121.     U_CloseFloating_window(theWS);                    { Call the user window close routine }
  122.  
  123.     SetPort(whichWindow);                            { Select our window }
  124.     theWindowLocRec.Loc_Floating_window.h := 0;        { Reset Horz position }
  125.     theWindowLocRec.Loc_Floating_window.v := 0;        { Reset Vert position }
  126.     LocalToGlobal(theWindowLocRec.Loc_Floating_window);    { Get global location }
  127.  
  128.     Mk_CloseLayeredWindow(whichWindow);                { Notify the layer code that we are closing }
  129.  
  130.     DisposeWindow(whichWindow);                        { Clear window and controls }
  131.  
  132.     ckWS := ListRecPtr_Floating_window;
  133.     if (ckWS = theWS) then                                { See if first in the list }
  134.         begin
  135.         ListRecPtr_Floating_window := theWS^.Next;    { Use second one as new first }
  136.         DisposePtr(Ptr(theWS));                        { Get rid of this one }
  137.         end
  138.     else
  139.         begin
  140.         while (ckWS <> nil) do                        { Loop thru them all }
  141.             begin
  142.             if (ckWS^.Next = theWS) then                { See if the next one is a match }
  143.                 begin
  144.                 ckWS^.Next := theWS^.Next;            { Get new next one }
  145.                 DisposePtr(Ptr(theWS));                { Get rid of this one }
  146.                 ckWS := nil;                            { Get us out of the loop }
  147.                 end
  148.             else
  149.                 ckWS := ckWS^.Next;                    { Try the next one }
  150.             end;
  151.         end;
  152.  
  153.     RecPtr_Floating_window := nil;                    { No active one }
  154.  
  155.     end;
  156. end;
  157.  
  158. { ======================================================= }
  159.  
  160. { Routine: Resized_Floating_window }
  161. { Purpose: We were resized or zoomed, update the scrolling scrollbars }
  162.  
  163. procedure Resized_Floating_window(OldRect:Rect;whichWindow:WindowPtr);
  164. var
  165.     SavePort:WindowPtr;                                { Place to save the last port }
  166.     temp2Rect:Rect;                                { temp rectangle }
  167.     Index:integer;                                    { temp integer }
  168.     ScrollHandle:ControlHandle;
  169.     theWS:Floating_windowPRec;
  170.  
  171.  
  172. begin
  173. LocateInstance(whichWindow);
  174.  
  175. if (RecPtr_Floating_window <> nil) then                    { Only do if the window is us }
  176.     begin
  177.     theWS := RecPtr_Floating_window;
  178.     
  179.     GetPort(SavePort);                                { Save the current port }
  180.     SetPort(whichWindow);                            { Set the port to my window }
  181.  
  182.     U_ResizedFloating_window(theWS,OldRect);        { Call the user window resized routine }
  183.  
  184.     SetPort(SavePort);                                { Restore the old port }
  185.     end;
  186. end;
  187.  
  188. { ======================================================= }
  189.  
  190. { Routine: Update_Floating_window }
  191. { Purpose: Update our window }
  192.  
  193. procedure Update_Floating_window(whichWindow:WindowPtr);
  194. var
  195.     SavePort:WindowPtr;                            { Place to save the last port }
  196.     Saved_ForeColor:RGBColor;                    { Place to save colors }
  197.     Saved_BackColor:RGBColor;                    { Place to save colors }
  198.     DrawingColor:RGBColor;                        { Place to make colors }
  199.     theWS:Floating_windowPRec;
  200.  
  201.  
  202. begin
  203. LocateInstance(whichWindow);
  204.  
  205. if (RecPtr_Floating_window <> nil)    then                { Only do if the window is us }
  206.     begin
  207.     theWS := RecPtr_Floating_window;
  208.  
  209.     GetPort(SavePort);                            { Save the current port }
  210.     SetPort(whichWindow);                        { Set the port to my window }
  211.  
  212.     if (Has.ColorQD) then                                { See if color QuickDraw is around }
  213.         begin
  214.         GetForeColor(Saved_ForeColor);            { Save the fore color }
  215.         GetBackColor(Saved_BackColor);            { Save the back color }
  216.  
  217.         RGBForeColor(Black_ForeColor);            { Set the fore color to Black }
  218.         RGBBackColor(White_BackColor);            { Set the back color to White }
  219.         end;                                        { End of IF }
  220.  
  221.  
  222.  
  223.     if (Has.ColorQD) then                                { See if color QuickDraw is around }
  224.         begin
  225.         RGBForeColor(Saved_ForeColor);            { Restore the fore color }
  226.         RGBBackColor(Saved_BackColor);            { Restore the back color }
  227.         end;
  228.  
  229.  
  230.     TextFont(applFont);                            { Back to the application font }
  231.     TextSize(12);                                { Back to the application size }
  232.     TextFace([]);                                { Set text style }
  233.  
  234.     U_UpdateFloating_window(theWS);            { Call the user window update routine }
  235.  
  236.     SetPort(SavePort);                            { Restore the old port }
  237.     end;
  238. end;
  239.  
  240. { ======================================================= }
  241.  
  242. { Routine: Open_Floating_window }
  243. { Purpose: Open our window }
  244.  
  245. procedure Open_Floating_window;
  246. var
  247.     BehindWindow:WindowPtr;                            { Used for window placement }
  248.     theLong:longint;                                { Used for icons and hotspots definition }
  249.     DefaultPosition:Point;                        { Used for window placement }
  250.     theWS:Floating_windowPRec;
  251.  
  252.  
  253. begin
  254. if ((ListRecPtr_Floating_window = nil) or (MultipleAllowed_Floating_window)) then
  255.     begin
  256.     theWS := Floating_windowPRec(NewPtrClear(sizeof(Floating_windowRec)));
  257.     RecPtr_Floating_window := theWS;
  258.     theWS^.Next := ListRecPtr_Floating_window;
  259.     ListRecPtr_Floating_window := theWS;
  260.     
  261.     InitRecord(theWS);
  262.  
  263.     BehindWindow := Mk_BehindWindow(6);            { Get which window to place below }
  264.  
  265.     if (Has.ColorQD) then                                { See if color QuickDraw is around }
  266.         theWS^.theWindow := GetNewCWindow(ResW_Floating_window,nil,BehindWindow)    { Get the COLOR window from the resource file }
  267.     else
  268.         theWS^.theWindow := GetNewWindow(ResW_Floating_window,nil,BehindWindow);{ Get the window from the resource file }
  269.     Mk_RegisterWindow(theWS^.theWindow,6);    { Register the window with the layers }
  270.     SetPort(theWS^.theWindow);                        { Prepare to write into our window }
  271.  
  272.     { Make a Palette }
  273.     theWS^.Ctrl_Tool_palette2 := MakePalette(theWS^.theWindow,ResC_Tool_palette2,
  274.         theWS^.Enable_Tool_palette2,10,2,ResC_N_Tool_palette2,6);
  275.  
  276.     SetPort(theWS^.theWindow);                        { Select our window }
  277.     DefaultPosition.h := 0;                            { Reset Horz position }
  278.     DefaultPosition.v := 0;                            { Reset Vert position }
  279.     LocalToGlobal(DefaultPosition);                { Get global location }
  280.     PositionWindow(theWS^.theWindow,theWindowLocRec.Loc_Floating_window,DefaultPosition);
  281.  
  282.     U_OpenFloating_window(theWS);                    { Call the users window open routine }
  283.  
  284.     ShowWindow(theWS^.theWindow);                    { Show the window now }
  285.  
  286.     end
  287. else
  288.     theWS := ListRecPtr_Floating_window;
  289.  
  290. Mk_HiliteWindow(theWS^.theWindow);                    { Already open, so show it }
  291. end;
  292.  
  293. { ======================================================= }
  294.  
  295. { Routine: Activate_Floating_window }
  296. { Purpose: We activated or deactivated }
  297.  
  298. procedure Activate_Floating_window(whichWindow:WindowPtr;Do_An_Activate:Boolean);
  299. var
  300.     SavePort:WindowPtr;                                { Place to save the last port }
  301.     theWS:Floating_windowPRec;
  302.  
  303.  
  304. begin
  305. LocateInstance(whichWindow);
  306.  
  307. if (RecPtr_Floating_window <> nil) then                    { Only do if the window is us }
  308.     begin
  309.     theWS := RecPtr_Floating_window;
  310.  
  311.     GetPort(SavePort);                                { Save the current port }
  312.     SetPort(whichWindow);                            { Set the port to my window }
  313.  
  314.     if (not(Do_An_Activate)) then                    { Handle the deactivate }
  315.         begin
  316.         if (theInput <> nil) then                    { See if there is already a TE area }
  317.             TEDeactivate(theInput);                    { Yes, so turn it off }
  318.         theInput := nil;                                { Deactivate the TE area }
  319.         end
  320.     else
  321.         begin
  322.         end;
  323.  
  324.     U_ActivateFloating_window(theWS,Do_An_Activate);    { Call the user window activate routine }
  325.  
  326.     SetPort(SavePort);                                { Restore the old port }
  327.     end;
  328. end;
  329.  
  330. { ======================================================= }
  331.  
  332. { Routine: Do_A_Button }
  333. { Purpose: Handle a button pressed }
  334.  
  335. procedure Do_A_Button(theWS:Floating_windowPRec;theControl:ControlHandle);    { Handle a button being pressed }
  336. var
  337.     RefCon:longint;                                    { RefCon for controls }
  338.     UnHiliteValue:integer;                            { For unhilite }
  339.     theSelection:integer;                            { For palettes and popups }
  340.  
  341.  
  342. begin
  343. if (theWS <> nil) then                                { Only do if the window is us }
  344.     begin
  345.     HiliteControl(theControl,10);                        { Darken the button }
  346.     UnHiliteValue := 0;                                    { To lighten the button }
  347.     RefCon := GetCRefCon(theControl);                    { get control refcon }
  348.     
  349.     case (RefCon) of                                    { Select correct button }
  350.         -1:begin end;
  351.         ResC_Tool_palette2:                { Tool palette, Tool palette }
  352.             begin
  353.             theWS^.Value_Tool_palette2 := GetCtlValue(theWS^.Ctrl_Tool_palette2);{ Get the palette value, 0xrrcc, rr is row, cc is column }
  354.             end;
  355.     
  356.         otherwise                                    { allow other buttons, trap for debug }
  357.             begin
  358.             end;                                { end of otherwise }
  359.         end;                                            { end of switch }
  360.     
  361.     U_DoButtonFloating_window(theWS,RefCon,theControl,UnHiliteValue);{ Call to handle any extra user buttons }
  362.     
  363.     HiliteControl(theControl,UnHiliteValue);            { Lighten the button }
  364.     end;
  365.  
  366. end;                                                    { End of Handle a button being pressed }
  367.  
  368. { ======================================================= }
  369.  
  370. { Routine: Do_Floating_window }
  371. { Purpose: Handle action to our window, like controls }
  372.  
  373. procedure Do_Floating_window(var myEvent:EventRecord);
  374. var
  375.     code:integer;                            { Location of event in window or controls }
  376.     whichWindow:WindowPtr;                    { Window pointer where event happened }
  377.     myPt:Point;                            { Point where event happened }
  378.     theControl:ControlHandle;                        { Handle for a control }
  379.     theWS:Floating_windowPRec;
  380.  
  381.  
  382. begin
  383. theWS := nil;
  384.  
  385. code := FindWindow(myEvent.where,whichWindow);    { Get where in window and which window }
  386.  
  387. LocateInstance(whichWindow);
  388.  
  389. if (RecPtr_Floating_window <> nil) then                    { Only do if the window is us }
  390.     begin
  391.     theWS := RecPtr_Floating_window;
  392.  
  393.     U_DoEventFloating_window(theWS,myEvent);
  394.  
  395.     if (myEvent.what = mouseDown) then
  396.         begin
  397.         myPt := myEvent.where;                    { Get mouse position }
  398.         GlobalToLocal(myPt);                    { Make it relative }
  399.  
  400.         end;
  401.  
  402.     if ((theWS^.theWindow = whichWindow) and (code = inContent)) then    { for our window }
  403.         begin
  404.         myPt := myEvent.where;                    { Get mouse position }
  405.         GlobalToLocal(myPt);                    { Make it relative }
  406.  
  407.         code := FindControl(myPt,whichWindow,theControl);    { Get type of control }
  408.  
  409.         if (code <> 0) then                            { Check type of control }
  410.             code := TrackControl(theControl,myPt,ProcPtr(-1));{ Track the control }
  411.         if (code = inButton) then
  412.             Do_A_Button(theWS,theControl);            { Do buttons }
  413.  
  414.         end;
  415.     end;
  416. end;
  417.  
  418. { ======================================================= }
  419. { ======================================================= }
  420. end.
  421.